package com.it.conformity.testdemo.controller;

import com.alibaba.fastjson.JSONObject;
import com.it.conformity.common.util.JsonResult;
import com.it.conformity.common.util.JsonResultT;
import com.it.conformity.testdemo.pojo.SysUser;
import com.it.conformity.testdemo.service.SysUserService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: 王文龙
 * @Date: 2020/6/1913:18
 * @Version: 1.0
 * @Describe: 描述:
 */
@RestController
@RequestMapping("/conformity/sysUser")
public class SysUserController {


    @Resource
    private SysUserService sysUserService;


    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public JSONObject insert(@RequestBody SysUser sysUser) {
        boolean insert = sysUserService.insert(sysUser);
        return JsonResult.success(insert);
    }



    @RequestMapping("/findById")
    public JsonResultT findById(Integer id) {
        try {
            SysUser byId = sysUserService.findById(id);
            if (byId != null) {
                return new JsonResultT<>(201, "查询成功", byId);
            } else {
                return new JsonResultT<>(210, "查询为空");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResultT<>(120, "信息出错", e.getMessage());
        }
    }
}
